package com.example.LoadData;

import java.util.Map;
import com.android.volley.AuthFailureError;
import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.Activity.MyApplication;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class LoadJson {

	private Context context;
	private Map<String, String> map;

	public LoadJson(Context context) {
		this(context, null);
		this.context = context;
	}

	public LoadJson(Context context, Map<String, String> map) {
		this.context = context;
		this.map = map;
	}

	public void getJSONByPost(String url) {
		StringRequest request = new StringRequest(Method.POST, url, new Listener<String>() {

			@Override
			public void onResponse(String arg0) {
				Toast.makeText(context, "success" + arg0, Toast.LENGTH_LONG).show();
			}
		}, new Response.ErrorListener() {

			@Override
			public void onErrorResponse(VolleyError arg0) {
				Toast.makeText(context, "error" + arg0.toString(), Toast.LENGTH_LONG).show();
			}
		}) {
			@Override
			protected Map<String, String> getParams() throws AuthFailureError {
				return map;
			}
		};
		request.setTag("abcPost");
		MyApplication.getRequestQueue().add(request);
	}

	public void getJSONByGet(String url) {
		StringRequest request = new StringRequest(Method.GET, url, new Listener<String>() {
			@Override
			public void onResponse(String arg0) {
				// TODO Auto-generated method stub
				Log.i("TAG", "success" + arg0);
			}
		}, new Response.ErrorListener() {

			@Override
			public void onErrorResponse(VolleyError arg0) {
				// TODO Auto-generated method stub
				Log.i("TAG", "error" + arg0.toString());
			}
		});
		request.setTag("abcGet");
		MyApplication.getRequestQueue().add(request);
	}
}
